package com.shengyin.ec.model.dao.permission;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.shengyin.ec.model.dao.BaseDaoImpl;
import com.shengyin.ec.model.entity.Resources;
import com.shengyin.ec.model.entity.Roles;

@Repository(value="resourcesDao")
public class ResourcesDaoImpl extends BaseDaoImpl<Resources> implements ResourcesDao {
	
	@Autowired
	RolesDao rolesDao;
	
	
	@Override
	public List<Resources> getResourcesList(int start, int end) {
		return super.findByPage("from Resources", start, end);
	}

	@Override
	public void deleteSelectedResources(Long[] ids) {
		Resources goods=null;
		List<Resources> goodsList=new ArrayList<Resources>(0);
		for(long id:ids)
		{
			goods=super.get(id);
			goodsList.add(goods);
		}
		
		super.deleteAll(goodsList);
		
	}
	@Override
	public Long getTotal(){
		return (Long) super.find("select count(*) from Resources").get(0);
	}

	@Override
	public List<Resources> getResourcesListByKeyword(String keyword, int start, int end) {
		return super.findByPage("from Resources", start, end);
	}

	@Override
	public Set<Resources> getResourcesListByRole(Long roleId, int start,
			int end) {
		Roles roles=rolesDao.get(roleId);
		return  roles.getResources();
	}


}
